package v1

import (
	"log"
	"net/http"

	"github.com/gin-gonic/gin"
	"gitee.com/laofa1/play/k_conf_mng/kconf_backend/models"
)

// LockConfTemplate to get a lock to edit configure template
func LockConfTemplate(c *gin.Context) {
	err := models.GetLock("confTemplateEditLock")
	if err != nil {
		log.Println(err)
		c.JSON(http.StatusOK, gin.H{
			"status": 10500,
			"data":   "lock fail",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"status": 10200,
		"data":   "",
	})
}

// UnLockConfTemplate to unlock configre template edit lock
func UnLockConfTemplate(c *gin.Context) {
	err := models.DeleteLock("confTemplateEditLock")
	if err != nil {
		log.Println(err)
		c.JSON(http.StatusOK, gin.H{
			"status": 10500,
			"data":   "unlock fail",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"status": 10200,
		"data":   "",
	})
}
